<template>
	<view class="popup-content">
		<!-- 优惠券列表 -->
		<!-- 优惠券列表 -->
		<view class="coupon-content" v-if="list.length">
			<view class="item flex flex-sb flex-wrap" v-for="(item,index) in list" :key="index">
				<view class="title-time">
					<view class="title">{{item.name}}</view>
					<view class="valid-time">{{item.expireType==10?`领取后${item.expireDay}天有效`:'有效期：'+item.expireDay}}
					</view>
				</view>
				<view class="price-condition">
					<view class="price">¥<text
							class="price-num">{{item.couponType==10?item.reducePrice:item.discount+'折'}}</text></view>
					<view class="condition">最低消费 {{item.minPrice}} 元</view>
				</view>
				<view class="split-line"></view>
				<view class="use-explain">
					<view class="title flex-sb">
						<view class="text" @click="explainUseChange(item.couponId)">使用说明
							<unt-icon :name="explainShow(item.couponId)?'icon-arrow-up':'icon-arrow-down'" size="14"
								:style="{marginLeft:'10rpx'}">
							</unt-icon>
						</view>
						<view class="use-btn" @click="handleDraw(item)">立即领取</view>
					</view>
					<view class="explain-content" v-show="explainShow(item.couponId)">
						<text class="li">{{item.description}}</text>
					</view>
				</view>
			</view>
		</view>
		<!-- 空列表 -->
		<unt-empty type='coupon' v-else></unt-empty>
		<!-- 空列表 -->
		<unt-empty type='coupon' v-else></unt-empty>
	</view>
</template>

<script>
	import {NewCoupon,draw} from '@/api/coupon/index.js'
	export default {
		data() {
			return {
				explain: {
					id: 0,
				},
				list: []
			}
		},
		onLoad() {
			this.getData();
		},
		methods: {
			getData() {
				NewCoupon().then(res => {
					this.list = res.data.yoshopCoupons;
				})
			},
			handleDraw(item) {
				draw({
					id: item.couponId
				}).then(res => {
					this.$unts.toast(res.message)
				})
			},
			explainUseChange(id) {
				this.explain.id == id ? this.explain.id = 0 : this.explain.id = id;
			},
			handleUseCoupon() {
				this.$unts.navTo('pages/index/index')
			}
		},
		computed: {
			explainShow() {
				return function(id) {
					return this.explain.id == id ? true : false;
				}
			}
		}
	}
</script>
<style>
	page {
		background-color: #F5F5F5;
	}
</style>
<style lang="scss" scoped>
	.popup-content {
		position: relative;
		width: 100%;
		height: 100vh;
		overflow: hidden;
		display: flex;
		flex-direction: column;
		align-items: center;
		// justify-content: center;

		.coupon-content {
			width: 100%;
			padding: 20rpx 30rpx;
			height: 100vh;
			overflow-y: auto;

			.item {
				padding: 25rpx;
				background: #fff;
				border-radius: 20rpx;
				// box-shadow: 20px 20px 29px #ebebeb, -2px -2px 5px #ebebeb;
				margin-bottom: 35rpx;

				.title-time {
					.title {
						font-weight: bold;
					}

					.valid-time {
						font-size: 28rpx;
						margin-top: 15rpx;
						color: #999;
					}
				}

				.price-condition {
					.price {
						color: #FC483C;
						text-align: right;

						.price-num {
							font-size: 40rpx;
							font-weight: bold;
						}
					}

					.condition {
						font-size: 28rpx;
						margin-top: 15rpx;
						color: #999;
					}
				}

				.split-line {
					width: 100%;
					position: relative;
					margin: 30rpx 20rpx 0rpx 20rpx;
					background: #F6F8FA;
					border-bottom: 1px dashed #999;

					&:before,
					{
					top: -15rpx;
					left: -60rpx;
				}

				&:after {
					right: -60rpx;
					bottom: -15rpx;
				}

				&:before,
				&:after {
					content: '';
					position: absolute;
					width: 35rpx;
					height: 35rpx;
					border-radius: 50%;
					background: #F6F8FA;
					z-index: 1;
				}


			}

			.use-explain {
				width: 100%;
				margin-top: 40rpx;

				.title {
					width: 100%;

					.text {
						font-size: 28rpx;
					}

					.use-btn {
						background-color: #04B97E;
						color: #FFFFFF;
						font-size: 28rpx;
						padding: 10rpx 25rpx;
						border-radius: 100rpx;
					}
				}

				.explain-content {
					width: 100%;

					.li {
						display: block;
						position: relative;
						font-size: 24rpx;
						margin: 10rpx 0px;
						padding-left: 20rpx;
						color: #999;
					}

					// .li:before {
					// 	content: "";
					// 	position: absolute;
					// 	left: 0;
					// 	top: calc(50% - 5rpx);
					// 	width: 10rpx;
					// 	height: 10rpx;
					// 	border-radius: 50%;
					// 	background-color: #999;
					// }
				}
			}
		}

	}

	// 
	}
</style>